<template>
	<view v-if="itemIndex===-1 && loadState" class="ad_banner">
		<ad @load="load" @close="close" @error="error" :style="diyStyle!=='null' ? diyStyle : ''" unit-id="adunit-86441a4d4fcc3f6d"></ad>
	</view>
	<template v-else>
		<view class="ad_banner" v-if="itemIndex===showIndex && loadState">
			<ad @load="load" @error="error" :ad-intervals="30" :style="diyStyle!=='null' ? diyStyle : ''" @close="close" unit-id="adunit-86441a4d4fcc3f6d"></ad>
		</view>
	</template>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	const props = defineProps({
		img:{
			type:String
		},
		height:{
			type:String,
			default:'calc(40vh)'
		},
		showIndex:{
			type:Number,
			default:1
		},
		itemIndex:{
			type:Number,
			default:-1
		},
		width:{
			type:String,
			default:"95%"
		},
		diyStyle:{
			type:String,
			default:"null"
		}
	})
	const loadState=ref(true)
	
	const error=()=>{
		loadState.value = false
	}
	const close=()=>{
		uni.$emit('tips','平台维护成本每天40元左右，非常抱歉广告给您造成了不好的体验，还望您谅解','info',2000)
	}
</script>

<style lang="less">
	.ad_banner{
		width: v-bind(width);
		margin-top: 20rpx;
	}
</style>